package com.qingcheng.service.impl;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;


/**
 * Created by yuanxin
 * Date:2019/7/7
 * Time:11:57
 */

public class RestClientFactory {

    public static RestHighLevelClient getRestHighLevelClient(String hostname,int port){
        //连接rest接口
        HttpHost httpHost = new HttpHost(hostname, port, "http");
        //设置超时时间
        RestClientBuilder builder = RestClient.builder(httpHost).setMaxRetryTimeoutMillis(5 * 60 * 1000);//rest构建器
        return new RestHighLevelClient(builder);//高级客户端对象
    }
}
